AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Initialize()
	self.Entity:SetModel("models/weapons/w_eq_fraggrenade.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	self.Entity:DrawShadow(false)
	self.Entity:SetCollisionGroup(COLLISION_GROUP_WEAPON)
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then phys:Wake() end
	timer.Simple(math.Rand(2.2,2.5), self.Explode, self)
	timer.Simple(0.2, self.Solidify, self)
end

function ENT:Solidify()
	self:SetOwner(self.Entity)
end

function ENT:Explode()
	if (ValidEntity(self.Owner)==false) then
		self.Entity:Remove()
	end
	
	util.BlastDamage(self.Entity, self.Owner, self.Entity:GetPos(), 384, 150)

	local effectdata = EffectData()
		effectdata:SetStart(self.Entity:GetPos())
		effectdata:SetOrigin(self.Entity:GetPos())
		effectdata:SetScale(1)
	util.Effect("HelicopterMegaBomb", effectdata)
	
	local effectdata2 = EffectData()
		effectdata2:SetStart(self.Entity:GetPos())
		effectdata2:SetOrigin(self.Entity:GetPos())
		effectdata2:SetScale(1)
	util.Effect("Explosion", effectdata2)

	self.Entity:EmitSound(Sound("weapons/hegrenade/explode"..math.random(3,5)..".wav"))
	self.Entity:Remove()
end